package cn.itrip.search.controller;
import cn.itrip.vo.ItripHotelSearchAllInfo;
import cn.itrip.dto.Dto;
import cn.itrip.search.service.HotelSearchService;
import cn.itrip.utlis.DtoUtils;
import cn.itrip.utlis.ErrorCode;
import cn.itrip.vo.hotel.SearchHotCityVO;
import cn.itrip.vo.hotel.SearchHotelVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
 * Created by LENOVO on 2018/8/23.
 */
@Controller
@RequestMapping("/api")
public class HotelSearchController {
    @Resource
    private HotelSearchService hotelSearchService;
    /**
     * 根据条件查询酒店里列表信息
     * @param searchHotelVO
     * @return
     */
    @ApiOperation(value="查询酒店里列表信息",httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="查询酒店里列表信息")
    @RequestMapping(value = "/hotellist/searchItripHotelPage", produces = "application/json", method = RequestMethod.POST)
    @ResponseBody
    public Dto searchItripHotelPage(@ApiParam(name="searchHotelVO",value="搜索条件",required=true)@RequestBody SearchHotelVO searchHotelVO)
    {
      ItripHotelSearchAllInfo itripHotelSearchAllInfo =null;
     try {
           itripHotelSearchAllInfo =hotelSearchService.searchItripHotelPage(searchHotelVO);
         }
        catch (Exception e) {
            e.printStackTrace();
            return DtoUtils.returnFail("获取酒店酒店列表信息失败！", ErrorCode.SEARCH_abnormal_FAILED);
        }
        if(itripHotelSearchAllInfo !=null)
        {
            return DtoUtils.returnSuccess("查询酒店列表成功!", itripHotelSearchAllInfo);
        }
        else
        {
            return DtoUtils.returnSuccess("没有酒店数据，请重新查询", itripHotelSearchAllInfo);
        }
    }

    /**
     * 根据热门城市查询酒店信息
     * @param searchHotCityVO
     * @return
     * @throws Exception
     */
    @ApiOperation(value="根据热门城市查询酒店信息",httpMethod = "POST", protocols = "HTTP", produces = "application/json", response = Dto.class,notes="根据热门城市查询酒店信息")
    @RequestMapping(value = "/hotellist/searchItripHotelListByHotCity", produces = "application/json", method = RequestMethod.POST)
    @ResponseBody
    public Dto searchItripHotelListByHotCity(@ApiParam(name="searchHotelVO",value="搜索条件",required=true)@RequestBody SearchHotCityVO searchHotCityVO) throws Exception {

      if(searchHotCityVO.getCityId()!=null)
      {
         ItripHotelSearchAllInfo itripHotelSearchAllInfo = hotelSearchService.searchItripHotelByHotCity(searchHotCityVO);
          if(itripHotelSearchAllInfo !=null)
          {
              return DtoUtils.returnSuccess("查询酒店列表成功!", itripHotelSearchAllInfo.getRows());
          }
          else
          {
              return DtoUtils.returnFail("没有酒店数据，请重新查询",ErrorCode.SEARCH_abnormal_FAILED);
          }
      }
      else
      {
         return DtoUtils.returnFail("酒店id为空",ErrorCode.SEARCH_ID_NULL);
      }
    }
}
